package com.ruoyi.wechat.service.impl;

import java.util.List;

import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.wechat.service.IImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wechat.mapper.CommonicationMapper;
import com.ruoyi.wechat.domain.Commonication;
import com.ruoyi.wechat.service.ICommonicationService;

/**
 * 营地交流Service业务层处理
 * 
 * @author 李硕
 * @date 2024-12-25
 */
@Service
public class CommonicationServiceImpl implements ICommonicationService 
{
    @Autowired
    private CommonicationMapper commonicationMapper;

    @Autowired
    private IImageService imageService;

    /**
     * 查询营地交流
     * 
     * @param commonicationId 营地交流主键
     * @return 营地交流
     */
    @Override
    public Commonication selectCommonicationByCommonicationId(String commonicationId)
    {
        return commonicationMapper.selectCommonicationByCommonicationId(commonicationId);
    }

    /**
     * 查询营地交流列表
     * 
     * @param commonication 营地交流
     * @return 营地交流
     */
    @Override
    public List<Commonication> selectCommonicationList(Commonication commonication)
    {
        return commonicationMapper.selectCommonicationList(commonication);
    }

    /**
     * 新增营地交流
     * 
     * @param commonication 营地交流
     * @return 结果
     */
    @Override
    public int insertCommonication(Commonication commonication)
    {
        return commonicationMapper.insertCommonication(commonication);
    }

    @Override
    public int WxInsertCommonication(Commonication commonication) {
        String uuid = IdUtils.randomUUID();
        commonication.setCommonicationId(uuid);
        for (int i = 0; i < commonication.getImageList().size(); i++) {
            commonication.getImageList().get(i).setCommonication(commonication.getCommonicationId());
            commonication.getImageList().get(i).setImageId(IdUtils.randomUUID());
            imageService.insertImage(commonication.getImageList().get(i));
        }
        int i = commonicationMapper.insertCommonication(commonication);
//        if (i >0) {
//            return uuid;
//        }
        return i;
    }

    /**
     * 修改营地交流
     * 
     * @param commonication 营地交流
     * @return 结果
     */
    @Override
    public int updateCommonication(Commonication commonication)
    {
        return commonicationMapper.updateCommonication(commonication);
    }

    /**
     * 批量删除营地交流
     * 
     * @param commonicationIds 需要删除的营地交流主键
     * @return 结果
     */
    @Override
    public int deleteCommonicationByCommonicationIds(String[] commonicationIds)
    {
        return commonicationMapper.deleteCommonicationByCommonicationIds(commonicationIds);
    }

    /**
     * 删除营地交流信息
     * 
     * @param commonicationId 营地交流主键
     * @return 结果
     */
    @Override
    public int deleteCommonicationByCommonicationId(String commonicationId)
    {
        return commonicationMapper.deleteCommonicationByCommonicationId(commonicationId);
    }
}
